#include "nodegraphics.h"

std::map<pair,NodeGraphics*,pairLess> NodeGraphics::NodesMap;
NodeGraphics *NodeGraphics::itemFocused = NULL;

NodeGraphics::NodeGraphics() {
    color = Qt::white;
    door.load(":/images/door.jpg");
    grama.load(":/images/grama.jpg");
    wall.load(":/images/wall.jpg");
    this->setAcceptHoverEvents(true);
}

void NodeGraphics::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
                         QWidget *widget)
{
    switch(type) {
    case WALL:
        color = Qt::black;
        painter->drawPixmap(0,0,wall);
        break;
    case PAS:
        color = Qt::blue;
        break;
    case OPEN:
        color = Qt::darkCyan;
        break;
    case CLOSE:
        color = Qt::darkYellow;
        break;
            case INIT:
        color = Qt::green;
        break;
    case END:
        painter->drawPixmap(0,0,door);
        break;
    case CAM_TMP:
        color = Qt::yellow;

        break;

    case EMPTY:
        painter->drawPixmap(0,0,grama);
        break;
    }
    if(type != WALL && type != EMPTY && type != END) {
        painter->setBrush(color);
        painter->drawPixmap(0,0,QPixmap(":/images/grama.jpg"));
        painter->drawEllipse (2,2,4,4);
        painter->drawEllipse (6,1,4,4);
        painter->drawEllipse (10,2,4,4);
        painter->drawEllipse (4,6,7,8);
    }
}


QRectF NodeGraphics::boundingRect() const {
    return QRectF(0, 0,17, 17);
}

void NodeGraphics::setType(LAB t){
    type = t;
}

QPainterPath NodeGraphics::shape() const
{
    QPainterPath path;
    path.addRect(0, 0, 17, 17);
    return path;
}

void NodeGraphics::mousePressEvent( QGraphicsSceneMouseEvent * event ) {
    //std::cout << "asdasd" << std::endl;
    if(event->button() == Qt::LeftButton)
        emit repaint(row,col,SET_SADDLES);
    else
        emit menuSignal(row,col,event->screenPos());
}


void NodeGraphics::setRowCol(int row_, int col_) {
    col = col_;
    row = row_;
}

void NodeGraphics::hoverEnterEvent ( QGraphicsSceneHoverEvent *event) {
    itemFocused = this;
    update();
}

void NodeGraphics::hoverLeaveEvent ( QGraphicsSceneHoverEvent *event){
    itemFocused = NULL;
    update();
}

